package com.atlin.project.fastDev;

import cn.hutool.core.io.FileUtil;

import static com.atlin.project.fastDev.TemplateConstants.*;

/**
 * @author atlin
 * @description 生成模版文件
 * @createDate 2024/12/5 20:39
 */
public class GenerateTemplate {


    public static void doGenerate() {
        // 目标路径
        String parent = System.getProperty("user.dir");
        String parentPath = parent + '/' + targetPath;
        String targetParentPath = parent + '/' + templateParentPath;

        // service
        String serviceStr = FileUtil.readUtf8String(parentPath + "/service/" + templateName + "Service.java");
        serviceStr = serviceStr.replaceAll("TempTemplate", "className_C")
                .replaceAll("tempTemplate", "className_L");

        FileUtil.writeString(serviceStr, targetParentPath + "/service/" + templateName + "Service.java", "UTF-8");

        // serviceImpl
        String serviceImplStr = FileUtil.readUtf8String(parentPath + "/service/impl/" + templateName + "ServiceImpl.java");
        serviceImplStr = serviceImplStr.replaceAll("TempTemplate", "className_C")
                .replaceAll("tempTemplate", "className_L");

        FileUtil.writeString(serviceImplStr, targetParentPath + "/service/impl/" + templateName + "ServiceImpl.java", "UTF-8");

        // controller
        String controllerStr = FileUtil.readUtf8String(parentPath + "/controller/" + templateName + "Controller.java");
        controllerStr = controllerStr.replaceAll("TempTemplate", "className_C")
                .replaceAll("tempTemplate", "className_L");

        FileUtil.writeString(controllerStr, targetParentPath + "/controller/" + templateName + "Controller.java", "UTF-8");

    }
}
